#!/bin/bash

# 测试故障分布图功能的脚本

echo "=== 测试故障分布图功能 ==="

# 1. 测试获取故障详情API
echo "1. 测试获取故障详情API..."
echo "测试机器J001的故障详情："
curl -s "http://localhost:8080/api/monitor/flaws/J001" | jq '.[0:5]' 2>/dev/null || echo "API调用失败或jq未安装"

# 2. 测试机器详情API（包含故障分布图）
echo -e "\n2. 测试机器详情API（包含故障分布图）..."
echo "测试机器1的详情数据："
curl -s "http://localhost:8080/api/monitor/machines/1/detail" | jq '.chartData.faultData | length' 2>/dev/null || echo "API调用失败或jq未安装"

# 3. 检查数据库中的故障数据
echo -e "\n3. 检查数据库中的故障数据..."
mysql -u root -p weaving_monitor -e "
SELECT 
    pf.type,
    pf.position,
    pf.time,
    ppc.machine_id
FROM prod_flaw pf
JOIN prod_product pp ON pf.product_id = pp.id
JOIN prod_prod_card ppc ON pp.card_id = ppc.id
WHERE ppc.status = '1'
LIMIT 10;
" 2>/dev/null || echo "数据库查询失败"

# 4. 显示故障类型映射
echo -e "\n4. 故障类型映射："
echo "0: 停车位"
echo "1: 横条"
echo "2: 断头"
echo "3: 长断头"
echo "4: 油污"
echo "5: 漏针"
echo "6: 其他"
echo "8: 抛丝"
echo "9: 吊丝"
echo "10: 勾丝"
echo "... (更多类型请参考app.js中的FLAW_TYPE_MAP)"

echo -e "\n=== 测试完成 ==="
echo "故障分布图现在使用真实的数据库数据，position作为x轴，type作为y轴"
